package com.lhn.bbs.controller;

import com.lhn.bbs.dto.ActionResult;
import com.lhn.bbs.entity.Plate;
import com.lhn.bbs.service.PlateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 板块
 */
@RequestMapping("/plate")
@RestController
@Slf4j
public class PlateController {

    @Autowired
    private PlateService plateService ;

    /**
     * 查询所有的板块
     * @return
     */
    @RequestMapping(value = "/plates",method = RequestMethod.GET)
    public ActionResult plates(){

        return plateService.findPlates();
    }
//    添加板块
    @RequestMapping(value = "/addplate",method = RequestMethod.POST)
    public ActionResult addplate(@RequestBody Plate plate){
//        创建时间
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
//        System.out.println(formatter.format(date));
        String format = formatter.format(date);
//        log.info(plate.getPlatename());
        plate.setPlatetime(format);
        plate.setPlateimg("http://qsrr7y19m.hn-bkt.clouddn.com/221956-16033763963867.jpg");
        return plateService.addPlate(plate);

    }
//    删除板块
    @RequestMapping(value = "/deleteplate",method = RequestMethod.GET)
    public ActionResult deleteplate(@RequestParam(value = "plateid") Integer plateid){

        return plateService.deleteplate(plateid);
    }



}
